﻿// Study1202.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
// 第十二章 异常处理 异常中的构造和析构

#include <iostream>
#include <string>
using namespace std;

class MyException
{
public:
	MyException(const string& message) :message(message) {  }
	~MyException() {}
	const string& getMessage() const
	{
		return message;
	}
private:
	string message;
};

class Demo
{
public:
	Demo() { cout << "Constructor of Demo" << endl; }
	~Demo() { cout << "Destructor of Demo" << endl; }
};
void func() throw(MyException)
{
	Demo d;
	cout << "Throw MyException in func（）" << endl;
	throw MyException("exception thrown by func()");
}
int main()
{
	cout << "In main function" << endl;
	try
	{
		func();
	}
	catch (MyException& e)
	{
		cout << "caught anexception: " << e.getMessage() << endl;

	}
	cout << "Resume the execution of main()" << endl;
	return 0;
}


